import TravelCityFlagItem from "./TravelCityFlagItem";
import UiManager from "./UiManage";

import n from "./AbTestMgr"
import l from "./PeripheralSystemDataMgr"
import s from "./EngineUtil"
import c from "./PageMgr"
import u from "./UiManage"
import p from "./TravelCityFlagItem"
import MatchGameData from "./MatchGameData";

const { ccclass, property } = cc._decorator;

@ccclass
export default class TravelCityFlagItemCtrl extends cc.Component {

    public ui;
    public cityId = null;
    public showLock = false;
    public isCreaseCity = false;
    public onLoad() {
        this.onUILoad();
        this.addButtonListen();
    };
    public start() { };
    public onUILoad() {
        this.ui = this.node.addComponent(p);
    };
    public addButtonListen() {
        u.addButtonListen(this.ui.reward, this.showTipsToast, this);
        u.addButtonListen(this.ui.rewardSpineNode, this.showTipsToast, this);
        u.addButtonListen(this.ui.rewardExperimentNode, this.showTipsToast, this);
        u.addButtonListen(this.ui.pandaTravel_reach_click_bg, this.showBeijingTipsToast, this);
    };
    public showTipsToast() {
        c.showPage("TravelToastPage", {
            type: 2,
            cityId: this.cityId
        });
    };
    public showBeijingTipsToast() {
        c.showPage("TravelBeiJingFlagToastPage", {
            type: 4,
            cityId: this.cityId
        });
    };
    public updategraybg(){
        this.ui.gray_bg.active = MatchGameData.gameLevel < this.cityId ;
    }
    public initData(e) {
        this.ui.pandaTravel_reach_click_bg.active = false;
        this.ui.numberNode.active = !0;
        if (e) {
            var t = e.cityId, a = e.tagNode, o = e.posData;
            if(t <= 0){
                this.node.active = false;
                return;
            }else{
                this.node.active = true;
            }
            this.cityId = t;
            this.ui.numberLabel.getComponent(cc.Label).string = t  + "";
            this.ui.numberGrayLabel.getComponent(cc.Label).string = t + "";
            this.ui.common_bg.active = true;
            this.ui.gray_bg.active = MatchGameData.gameLevel < t ;
            this.ui.numberLabel.active = false;
            this.ui.numberGrayLabel.active = !0;

            if(o){
                // var i = this.node.parent.convertToNodeSpaceAR(a.parent.convertToWorldSpaceAR(cc.v2(o.x, o.y)));
                this.node.setPosition(o);
                debugger
            }
           
            this.isCreaseCity = this.isHaveInCreaseCity();
            var r = n.isOptimizeTravelFundFlag();
            if (this.isCreaseCity) {
                this.ui.rewardSpineNode.active = !0;
                this.ui.reward.active = false;
                this.ui.rewardExperimentNode.active = false;
                // this.node.scale = 1.25;
            } else {
                this.ui.rewardSpineNode.active = false;
                if (r) {
                    this.ui.reward.active = false;
                    this.ui.rewardExperimentNode.active = !0;
                } else {
                    this.ui.reward.active = !0;
                    this.ui.rewardExperimentNode.active = false;
                }
                // this.node.scale = 1;
            }
        }
    };
    public isHaveInCreaseCity() {
        return -1 !== (n.getIsTxtjsy() ? l.INCREASE_CITY_ARR2.indexOf(this.cityId + 1) : l.INCREASE_CITY_ARR.indexOf(this.cityId + 1));
    };
    public setLockShow(e) {
        this.ui.numberGrayLabel.active = e;
        this.ui.gray_bg.active = e;
        this.ui.numberLabel.active = !e;
        this.ui.common_bg.active = !e;
        this.showLock = e;
        this.isCreaseCity ? this.ui.rewardSpineNode.active = e : n.isOptimizeTravelFundFlag() ? this.ui.rewardExperimentNode.active = e : this.ui.reward.active = e;
    };
    public lockShake() {
        cc.tween(this.ui.numberNode).repeat(8, cc.tween().by(.1, {
            angle: -10
        }).by(.1, {
            angle: 10
        }).by(.1, {
            angle: 10
        }).by(.1, {
            angle: -10
        })).start();
    };
    public playUnLockSpine(e) {
        var t = this;
        this.ui.lockSpineNode.active = !0;
        this.ui.gray_bg.active = false;
        var a = this.ui.lockSpineNode.getComponent(sp.Skeleton);
        s.playSpine(a, "idle_2", false, function () {
            t.ui.common_bg.active = !0;
            var a = n.isOptimizeTravelFundFlag();
            t.isCreaseCity ? t.ui.rewardSpineNode.active = false : a ? t.ui.rewardExperimentNode.active = false : t.ui.reward.active = false;
            e && e();
        });
    };
    public setBeiJingRewardFlagShow() {
        this.ui.pandaTravel_reach_click_bg.active = !0;
        this.ui.numberNode.active = false;
    };

    static prefabUrl = "assets/resources/prefabs/TravelCityFlagItem";
    static className = "TravelCityFlagItemCtrl";
}